package com.xhcl.web.controller.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.druid.util.StringUtils;
import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TGgKmdm;
import com.xhcl.system.domain.TSrhsAccountTemp;
import com.xhcl.system.domain.TSrhsHsxtcs;
import com.xhcl.system.domain.TSrhsPzto;
import com.xhcl.system.service.ITGgKmdmService;
import com.xhcl.system.service.ITSrhsAccountTempService;
import com.xhcl.system.service.ITSrhsHsxtcsService;
import com.xhcl.system.service.ITSrhsPztoService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 银行日记账
 * 
 * @author xhcl
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/system/bankaccount")
public class TSrhsBankAccountController extends BaseController
{
    private String prefix = "system/bankaccount";

    @Autowired
    private ITSrhsPztoService tSrhsPztoService;
    
    @Autowired
    private ITGgKmdmService tGgKmdmService;
    
    @Autowired
    private ITSrhsHsxtcsService tSrhsHsxtcsService;
    
    @Autowired
    private ITSrhsAccountTempService tSrhsAccountTempService;

    @RequiresPermissions("system:bankaccount:view")
    @GetMapping()
    public String bankaccount(ModelMap mmap)
    {   TGgKmdm tGgKmdm=new TGgKmdm();
    	tGgKmdm.getParams().put("sjkmdm", "101");
    	List<TGgKmdm> list=tGgKmdmService.selectTGgKmdmList(tGgKmdm); 
    	mmap.put("kmdmlist", list);
    	String year=tSrhsHsxtcsService.getHsxtcsnr("year");
    	String term=tSrhsHsxtcsService.getHsxtcsnr("term");
    	List<String> ndlist=new ArrayList();
    	for (int i=0;i<5;i++) {
    		ndlist.add(String.valueOf(Integer.parseInt(year)-i));
    	}
    	mmap.put("ndlist", ndlist);
    	mmap.put("year", year);
    	List<String> yflist=new ArrayList();
    	for (int i=1;i<=12;i++) {
    		yflist.add(String.valueOf(i));
    	}
    	mmap.put("yflist", yflist);
    	mmap.put("term", term);
        return prefix + "/bankaccount";
    }

    /**
     * 查询
     */
    @RequiresPermissions("system:bankaccount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSrhsAccountTemp tSrhsAccountTemp)
    {  
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("nd", StringUtils.stringToInteger(tSrhsAccountTemp.getParams().get("nd")==null?"":tSrhsAccountTemp.getParams().get("nd").toString()));
    	map.put("syf", StringUtils.stringToInteger(tSrhsAccountTemp.getParams().get("syf")==null?"":tSrhsAccountTemp.getParams().get("syf").toString()));
    	map.put("eyf", StringUtils.stringToInteger(tSrhsAccountTemp.getParams().get("eyf")==null?"":tSrhsAccountTemp.getParams().get("eyf").toString()));
    	map.put("kmdm", tSrhsAccountTemp.getParams().get("kmdm"));
    	map.put("sfjz", tSrhsAccountTemp.getParams().get("sfjz")==null?0:(tSrhsAccountTemp.getParams().get("sfjz").equals("on")?1:0));
    	List<TSrhsAccountTemp> list = tSrhsAccountTempService.selectBankAccount(map);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @RequiresPermissions("system:bankaccount:export")
    @Log(title = "银行日记账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsAccountTemp tSrhsAccountTemp)
    {   
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("nd", StringUtils.stringToInteger(tSrhsAccountTemp.getParams().get("nd")==null?"":tSrhsAccountTemp.getParams().get("nd").toString()));
    	map.put("syf", StringUtils.stringToInteger(tSrhsAccountTemp.getParams().get("syf")==null?"":tSrhsAccountTemp.getParams().get("syf").toString()));
    	map.put("eyf", StringUtils.stringToInteger(tSrhsAccountTemp.getParams().get("eyf")==null?"":tSrhsAccountTemp.getParams().get("eyf").toString()));
    	map.put("kmdm", tSrhsAccountTemp.getParams().get("kmdm"));
    	map.put("sfjz", tSrhsAccountTemp.getParams().get("sfjz")==null?0:(tSrhsAccountTemp.getParams().get("sfjz").equals("on")?1:0));
    	List<TSrhsAccountTemp> list = tSrhsAccountTempService.selectBankAccount(map);
        ExcelUtil<TSrhsAccountTemp> util = new ExcelUtil<TSrhsAccountTemp>(TSrhsAccountTemp.class);
        return util.exportExcel(list, "pzto");
    }

     
}
